﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BasMaterialInfoList.aspx.cs" Inherits="JYH.Web.MES.BAS.UI.BasMaterialInfoList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <link rel="stylesheet" type="text/css" href="../../themes/uimaker/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/uimaker.css" />
    <link rel="stylesheet" type="text/css" href="../../font/iconfont.css" />
        <link rel="stylesheet" type="text/css" href="../../font/icon.css" />
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../js/JYH.Core.js"></script>
       <script type="text/javascript" src="../../js/xlsx.full.min.js"></script>
   <script type="text/javascript" src="../../js/FileSaver.min.js"></script>
    <title>物料物料信息</title>
    <script type="text/javascript">
        $(function () {
            $('#tt').datagrid({
                loadMsg: "正在接收数据...",
                iconCls: 'icon-reload',
                idField: 'MaterialID',
                autoRowHeight: true,
                fitColumns: false,
                scrollbarSize: 0,
                pageSize: 20,
                striped: true,      //隔行变色
                singleSelect: true, //是否单选
                pagination: true,   //分页控件
                rownumbers: true,
                columns: [[
                    { field: 'IsSelect', checkbox: true },
                    { field: 'MaterialID', hidden: true },
                    //{ field: 'MaterialType', hidden: true },
                    { field: 'MaterialNO', width: 120, title: '物料编号', sortable: true },
                    { field: 'MaterialName', width: 120, title: '物料名称' },
                    { field: 'MaterialDesc', width: 150, title: '物料规格' },
                    { field: 'Humidity', width: 120, title: '湿敏等级' },
                    { field: 'StockQty', title: '最低库存' },
                    { field: 'WarrantyDay', title: '保质天数' },
                    { field: 'YokePlate', title: '装箱规格' },
                    { field: 'Exceeding', title: '超领数量' },
                    { field: 'CreateTime', title: '创建时间', sortable: true },
                    { field: 'CreateUser', title: '创建人员' },
                    { field: 'UpdateTime', title: '修改时间' },
                    { field: 'UpdateUser', title: '修改人员' }
                ]],
                onLoadSuccess: function (data) {
                    $('#tt').datagrid("fillRows");
                    $('#tt').datagrid('resize');
                },
                onDblClickRow: function (index, row) {
                    if (row == null) {
                        Alert("请选择一行数据");
                        return false;
                    }
                    $('#hMaterialID').val(row.MaterialID);
                    $("#txtMaterialNO").textbox('setValue', row.MaterialNO);
                    $("#txtMaterialName").textbox('setValue', row.MaterialName);
                    $('#txtHumidity').textbox('setValue', row.Humidity);
                    $('#txtMaterialDesc').textbox('setValue', row.MaterialDesc);
                    $('#txtStockQty').textbox('setValue', row.StockQty);
                    $('#txtExceeding').textbox('setValue', row.Exceeding);
                    $('#txtWarrantyDay').textbox('setValue', row.WarrantyDay);
                    $('#txtYokePlate').textbox('setValue', row.YokePlate);
                    document.getElementById('btnSave').style.display = 'none';//inline
                    //document.getElementById('ids').style.display = 'none';//inline
                    $('#dd').drawer('expand');

                },
                onSortColumn: function (order, sort) {
                    $("#hSort").val(sort);
                    $("#hOrder").val(order);
                    /*       loadLocal();*/
                },
            });
            $(window).resize(function () {
                $('#tt').datagrid('resize');
            });
            //绑定抽屉打开事件
            $('#dd').drawer({
                onExpand: function () {

                }
            });
            //绑定抽屉关闭事件
            $('#dd').drawer({
                onCollapse: function () {
                    // 抽屉关闭后的逻辑处理
                    console.log('抽屉已关闭');
                    // 添加您想要执行的操作
                }
            });
            $('#tt').datagrid('unselectAll');
        })

        //新增取消
        function ItemClear() {
            $('#dd').drawer({
                onCollapse: function () {
                    // 抽屉关闭后的逻辑处理
                    console.log('抽屉已关闭');
                    // 添加您想要执行的操作
                }
            });
            $('#tt').datagrid('unselectAll');
            $('#dd').find('input.easyui-textbox').textbox('setValue', '');
        }
        //查询
        function loadLocal() {
            var MaterialNO = $("#qMaterialNO").val();//编号
            var MaterialName = $("#qMaterialName").val();//名称
            //排序字段
            var sort = $("#hSort").val();
            var order = $("#hOrder").val();
            $("#tt").datagrid({
                url: '/api/BAS/QueryMaterial',
                method: 'Get',
                queryParams: {
                    MaterialNO: MaterialNO,
                    MaterialName: MaterialName,
                    sort: sort,
                    order: order
                },
                loadFilter: function (data) {
                    if (data.d) {
                        return data.d;
                    } else {
                        return JSON.parse(data);
                    }

                }
            });
            $('#tt').datagrid('unselectAll');
        }

        //新增弹窗
        function AddNew() {
            $('#dd').find('input.easyui-textbox').textbox('setValue', '');
            $('#hMaterialID').val("");
            $('#txtStockQty').textbox('setValue', "1");
            $('#txtExceeding').textbox('setValue', "1");
            $('#txtWarrantyDay').textbox('setValue', "1");
            $('#txtYokePlate').textbox('setValue', "1");
            $('#txtMaterialNO').textbox('readonly', false);
            document.getElementById('btnSave').style.display = '';//inline
            //document.getElementById('ids').style.display = '';//inline
            $('#dd').drawer('expand');
        }

        function validateForm() {
            var isValid = true;
            // 获取所有带有 required 属性的输入字段
            var requiredFields = document.querySelectorAll('input[required]');

            requiredFields.forEach(function (field) {
                if (field.value.trim() === '') {
                    isValid = false;
                    Alert(field.getAttribute('data-options').split(':')[1].replace(/'/g, '').trim() + ' 是必填项');
                    field.focus();
                    return false;
                }
            });

            return isValid;
        }

        function SaveMaterial() {
            if (!validateForm()) {
                return;
            }
            var MateialID = $('#hMaterialID').val();
            var MaterialNO = $('#txtMaterialNO').textbox('getValue');
            //var MaterialType = $('#txtMaterialType').combobox('getValue');
            var Humidity = $('#txtHumidity').textbox('getValue');
            var MaterialName = $('#txtMaterialName').textbox('getValue');
            var MaterialDesc = $('#txtMaterialDesc').textbox('getValue');
            var StockQty = $('#txtStockQty').textbox('getValue');
            var Exceeding = $('#txtExceeding').textbox('getValue');
            var WarrantyDay = $('#txtWarrantyDay').textbox('getValue');
            var YokePlate = $('#txtYokePlate').textbox('getValue');
            var UserNO = "";
            const cookies = document.cookie.split('; ');
            for (const cookie of cookies) {
                const [name, value] = cookie.split('=');
                if (name.indexOf('MES_USER_LOGIN_CookieName') >= 0) {
                    UserNO = value;
                    break;
                }
            }
            var MateialInfo = {
                MateialID: MateialID,
                MaterialNO: MaterialNO,
                Humidity: Humidity,
                MaterialName: MaterialName,
                MaterialDesc: MaterialDesc,
                StockQty: StockQty,
                Exceeding: Exceeding,
                WarrantyDay: WarrantyDay,
                YokePlate: YokePlate,
                CreateUser: UserNO
            };
            var url = '/api/BAS/SaveMaterial';
            DataService.PostJson(url, MateialInfo, function (err, res) {
                if (err) {
                    Notice("Success!");
                    loadLocal();
                } else {
                    Notice("保存失败." + res);
                }
            });
            ItemClear();
            $('#dd').find('input.easyui-textbox').textbox('setValue', '');

        }
        //删除
        function Delet() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length < 1) {
                Alert("请选择后再删除！");
                return false;
            }
            Confirm("确定要删除吗？", function () {
                var MateialInfo =fnSelectList('tt',rows);
                var url = '/api/BAS/DeleteMaterial';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("Success!");
                    } else {
                        Alert("删除失败!"+response);
                    }
                    loadLocal();
                })

            });
        }

        //审核
        function Check() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length < 1) {
                Alert("请选择后再审核！");
                return false;
            }
            Confirm("确定要审核吗？", function () {
                var MateialInfo = fnSelected(rows, $("#tt").datagrid('options').columns[0]);
                var url = '/api/BAS/ApproveMaterial';

                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("Success!");
                    } else {

                        Alert("审核失败!" + response);
                    }
                    loadLocal();
                })

            });
        }

        //反审
        function UnCheck() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length < 1) {
                Alert("请选择后再反审！");
                return false;
            }
            Confirm("确定要反审吗？", function () {
                var MateialInfo = fnSelected(rows, $("#tt").datagrid('options').columns[0]);
                var url = '/api/BAS/UpdoMaterial';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("Success!");

                    } else {
                        Alert("反审失败!" + response);
                    }
                    loadLocal();
                })

            });
        }


        function Update() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length != 1) {
                Alert("修改需要选择一行数据!");
                return false;
            }
            var row = rows[0];
            if (row == null) {
                Alert("修改需要选择一行数据");
                return false;
            }
            $('#hMaterialID').val(row.MaterialID);
            $("#txtMaterialNO").textbox('setValue', row.MaterialNO);
            $('#txtMaterialNO').textbox('readonly', true);
            $("#txtMaterialName").textbox('setValue', row.MaterialName);
            $('#txtHumidity').textbox('setValue', row.Humidity);
            $('#txtMaterialDesc').textbox('setValue', row.MaterialDesc);
            $('#txtStockQty').textbox('setValue', row.StockQty);
            $('#txtExceeding').textbox('setValue', row.Exceeding);
            $('#txtWarrantyDay').textbox('setValue', row.WarrantyDay);
            $('#txtYokePlate').textbox('setValue', row.YokePlate);
            document.getElementById('btnSave').style.display = '';//inline
            //document.getElementById('ids').style.display = '';//inline
            $('#dd').drawer('expand');
            $('#tt').datagrid('unselectAll');

        }

        function ExeclTo() {
            OpenWindow("物料物料信息导入", "BAS/UI/BasMaterialEdit.aspx", 500, 280, function () {
                loadLocal();
            });
        }
        function Synch() {
            var SynchName = "SyncMaterialInfo";
            OpenWindow("资料同步", "Public/UI/BasSynchronousInfo.aspx?SynchName=" + SynchName, 300, 200, function () {
                loadLocal();
            });
        }
    </script>
</head>
<body>

      
        <div class="pagebox">
            <div class="cbox">
                <!--工具栏-->
                <div class="easyui-panel" style="padding: 15px; width: 100%;">
                    <div id="tb">
                        <ul class="flist">
                            <li>
                                <input class="easyui-textbox" type="text" id="qMaterialNO" data-options="prompt:'请输入物料编号'" style="width: 250px; height: 35px; line-height: 35px;" /></li>
                            <li>
                                <input class="easyui-textbox" type="text" id="qMaterialName" data-options="prompt:'请输入物料名称'" style="width: 250px; height: 35px; line-height: 35px;" /></li>
                        </ul>
                        <div>
                            <a href="javascript:void(0)" class="easyui-linkbutton c1" onclick="loadLocal()" data-options="iconCls:'icon-sousuo',selected:true">查询</a>
                            <a href="#" class="easyui-linkbutton c4" data-options="iconCls:'icon-tianjia'" onclick="AddNew()">新增</a>
                            <a href="#" class="easyui-linkbutton c7" data-options="iconCls:'icon-bianji'" onclick="Update()">修改</a>
                            <a href="#" class="easyui-linkbutton c2" data-options="iconCls:'icon-buchongiconsvg13'" onclick="Delet()">删除</a>
                            <a href="#" class="easyui-linkbutton c8" data-options="iconCls:'icon-xiangxia'"  id="BtnSync" onclick="Synch()">同步</a>
<%--                             <a href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-zujian-'" onclick="ExeclTo()">Exexl导入</a>
                            <a href="#" class="easyui-linkbutton c7" data-options="iconCls:'icon-xiangmu1'" onclick="ToExcel('tt','')">导出</a>--%>
                        </div>

                    </div>
                </div>
            </div>
            <div class="cbox">
                <!--查询结果清单-->
                <table id="tt" title="物料列表">
                
                </table>
            </div>
        </div>
        <form id="ff" runat="server">
              <%--排序隐藏值--%>
        <asp:HiddenField runat="server" ID="hSort" />
        <asp:HiddenField runat="server" ID="hOrder" />
           <asp:HiddenField ID="hMaterialID" runat="server" />
                <div id="dd" class="easyui-drawer f-column" style="width: 550px;">
                 
                <div style="line-height: 30px; text-align: center; border-bottom: 1px solid #ddd">物料物料信息</div>
                <div class="f-full">
                    <ul style="margin: 10px;">
                       
                        <li style="margin-bottom: 15px; padding-left: 10px;">
                            <input class="easyui-textbox" id="txtMaterialNO" style="width: 45%; height: 32px;"   data-options="label:'物料编号:'"  runat="server" required="required"/>
                         <%--   <select class="easyui-combobox" id="txtMaterialType" height: 32px;" panelHeight="auto" data-options="label:'数据类型:'"  style="width:45%;">                          
                                                       <option value="1">物料</option>
                                                       <option value="0">物料</option>
                                                       <option value="2">部件</option>
                                                       <option value="3">虚拟件</option>
                           </select>--%>
                            &nbsp&nbsp&nbsp&nbsp
                              <input class="easyui-textbox" id="txtHumidity" style="width: 45%; height: 32px; " data-options="label:'湿敏等级:'"  runat="server" />
                        </li>
                        <li style="margin-bottom: 15px; padding-left: 10px;">
                            <input class="easyui-textbox" id="txtMaterialName" style="width: 95%; height: 32px;" data-options="label:'物料名称:'" required="required" runat="server"/>
                        </li>
                         <li style="margin-bottom: 15px; padding-left: 10px;">
                            <input class="easyui-textbox" id="txtMaterialDesc" style="width: 95%; height: 32px;" data-options="label:'物料规格:'" required="required" runat="server" multiple="multiple" />
                        </li>
                       <li style="margin-bottom: 15px; padding-left: 10px;">
                            <input class="easyui-textbox" id="txtStockQty" style="width: 45%; height: 32px;" data-options="label:'最低库存:'" value="0" runat="server" />
                            &nbsp&nbsp&nbsp&nbsp
                            <input class="easyui-textbox" id="txtExceeding" style="width: 45%; height: 32px; " data-options="label:'超领数量:'" value="0"  runat="server"  />
                        </li>
                        <li style="margin-bottom: 15px; padding-left: 10px;">
                            <input class="easyui-textbox" id="txtWarrantyDay" style="width: 45%; height: 32px;" data-options="label:'保质天数:'" value="0"  runat="server"/>
                              &nbsp&nbsp&nbsp&nbsp
                            <input class="easyui-textbox" id="txtYokePlate" style="width: 45%; height: 32px; " data-options="label:'装箱规格:'" value="0"  runat="server"  required/>
                        </li>
                    </ul>
                </div>
                    <style>
                        .blue-text {
                            color: blue;
                        }
                    </style>
                <div style="padding: 5px; text-align: center; border-top: 1px solid #ddd">
                    <a href="javascript:;" id="btnSave" class="easyui-linkbutton c1" onclick="SaveMaterial()">保存</a>
                    <a href="javascript:;" class="easyui-linkbutton c2" onclick="ItemClear()">取消</a>
                </div>

            </div>
         
                </form>

</body>
</html>
